package ch.hearc.coursJava.kitBase.de.excel;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UseTestRandomTest
	{

	/*------------------------------------------------------------------*\
	 |*							Constructeurs							*|
	 \*------------------------------------------------------------------*/

	@Before
	public void before()
		{
		// rien
		}

	@After
	public void after()
		{
		// rien
		}

	/*------------------------------------------------------------------*\
	 |*							Methodes Public							*|
	 \*-----------------------------------------------------------------*/

	@Test
	public void testFill()
		{
		int nbPossibility = 6;
		int n = 100000;
		int[] tabPossibility = new int[nbPossibility];

		UseTestRandom.fill(tabPossibility, n);

		assertTrue(isNotNull(tabPossibility));

		tabPossibility[0] = 0;

		assertFalse(isNotNull(tabPossibility));
		}

	@Test
	public void testIsNumberInteger()
		{
			{
			String a = "salut";
			assertFalse(UseTestRandom.isNumberInteger(a));
			}

			{
			String b = "1234";
			assertTrue(UseTestRandom.isNumberInteger(b));
			}

			{
			String c = "45bv";
			assertFalse(UseTestRandom.isNumberInteger(c));
			}

			{
			String d = "45.12";
			assertFalse(UseTestRandom.isNumberInteger(d));
			}

			{
			String e = "dss355";
			assertFalse(UseTestRandom.isNumberInteger(e));
			}
		}

	@Test
	public void argsToMap()
		{
		String[] tabA = new String[]{"b=20", "a=100", "c=toto"};
		String separator = "=";

		Map<String, String> map = UseTestRandom.argsToMap(tabA, separator);

		assertTrue(tabA.length == map.size());
		assertTrue(map.containsKey("a") && map.containsKey("c") && map.containsKey("b"));
		assertTrue(map.containsValue("100") && map.containsValue("toto") && map.containsValue("20"));

		assertFalse(map.containsKey("d"));

		}
	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private static boolean isNotNull(int[] tabPossibility)
		{
		for(int elem:tabPossibility)
			{
			if(elem == 0)
				{
				return false;
				}
			}
		return true;
		}
	}
